package com.iary.infrastructure.orm.mybatis;

import java.util.List;

import org.mybatis.spring.support.SqlSessionDaoSupport;
import org.springframework.stereotype.Component;

import com.iary.domain.model.block.Block;
import com.iary.domain.model.block.BlockRepository;
import com.iary.domain.model.block.BlockType;

@Component
public class BlockRepositoryImpl extends SqlSessionDaoSupport implements
		BlockRepository {

	@Override
	public Block get(Long id) {
		return (Block) getSqlSession().selectOne("Block.getBlockById", id);
	}

	@Override
	public void insert(Block block) {
		getSqlSession().insert("Block.insert", block);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Block> getBlocksByType(BlockType blockType) {
		return getSqlSession().selectList("Block.getBlocksByType", blockType);
	}

	@Override
	public void update(Block block) {
		getSqlSession().update("Block.update", block);
	}

}
